import { Entity, PrimaryGeneratedColumn, Column, OneToOne, ManyToOne, JoinColumn } from "typeorm";
import { ManualTimestamp } from "../decorators/manual-timestamp.decorator";
import { CharacterEntity } from "./character.entity";
import { CharacterEquipmentInventoryEntity } from "./character-equipment-inventory.entity";

@Entity("character_equipment")
@ManualTimestamp()
export class CharacterEquipmentEntity {
  @PrimaryGeneratedColumn({ comment: "主键ID" })
  id!: number;

  @Column("int", { name: "characterId", comment: "角色ID" })
  characterId!: number;

  @Column("int", { nullable: true, comment: "右手武器装备ID" })
  rightHand!: number | null;

  @Column("int", { nullable: true, comment: "身体铠甲装备ID" })
  body!: number | null;

  @Column("int", { nullable: true, comment: "头部头盔装备ID" })
  head!: number | null;

  @Column("int", { nullable: true, comment: "颈部项链装备ID" })
  neck!: number | null;

  @Column("int", { nullable: true, comment: "左手护腕装备ID" })
  leftHand!: number | null;

  @Column("int", { nullable: true, comment: "脚部战靴装备ID" })
  foot!: number | null;

  // 支持动态属性访问
  [key: string]: any;

  @Column("datetime", { name: "created_at", comment: "创建时间" })
  created_at!: Date;

  @Column("datetime", { name: "updated_at", nullable: true, comment: "更新时间" })
  updated_at!: Date | null;

  // 关联关系
  @OneToOne(() => CharacterEntity, (character) => character.equipment)
  @JoinColumn({ name: "characterId" })
  character!: CharacterEntity;

  // 装备关联关系
  @ManyToOne(() => CharacterEquipmentInventoryEntity, { nullable: true })
  @JoinColumn({ name: "rightHand" })
  rightHandEquipment!: CharacterEquipmentInventoryEntity;

  @ManyToOne(() => CharacterEquipmentInventoryEntity, { nullable: true })
  @JoinColumn({ name: "body" })
  bodyEquipment!: CharacterEquipmentInventoryEntity;

  @ManyToOne(() => CharacterEquipmentInventoryEntity, { nullable: true })
  @JoinColumn({ name: "head" })
  headEquipment!: CharacterEquipmentInventoryEntity;

  @ManyToOne(() => CharacterEquipmentInventoryEntity, { nullable: true })
  @JoinColumn({ name: "neck" })
  neckEquipment!: CharacterEquipmentInventoryEntity;

  @ManyToOne(() => CharacterEquipmentInventoryEntity, { nullable: true })
  @JoinColumn({ name: "leftHand" })
  leftHandEquipment!: CharacterEquipmentInventoryEntity;

  @ManyToOne(() => CharacterEquipmentInventoryEntity, { nullable: true })
  @JoinColumn({ name: "foot" })
  footEquipment!: CharacterEquipmentInventoryEntity;
}
